package com.zlc.atonce.huarongdao.algorithme;

import com.zlc.atonce.Util.Point;

class CellCoder {
    public static final int UP_MASK = 1;
    public static final int DOWN_MASK = 1 << 1;
    public static final int LEFT_MASK = 1 << 2;
    public static final int RIGHT_MASK = 1 << 3;
    public static final int TYPE_EMPTY = 1 << 4;
    public static final int TYPE_SINGLE = 1 << 5;
    public static final int TYPE_H_TWO = 1 << 6;
    public static final int TYPE_V_TWO = 1 << 7;
    public static final int TYPE_FOUR = 1 << 8;

    public static boolean isBlank(int id) {
        return (id & TYPE_EMPTY) == TYPE_EMPTY;
    }

    public static boolean isBlank(char id) {
        return id == Cell.BLANK.charCode;
    }

    // 获取相对左上角的偏移量
    public static Point offset2LU(int id) {
        if (isBlank(id)) {
            return Point.of(0, 0);
        }
        int y = (id & LEFT_MASK) == LEFT_MASK ? 0 : -1;
        int x = (id & UP_MASK) == UP_MASK ? 0 : -1;
        return Point.of(x, y);
    }
}
